/**
 * 
 */
package lt.vin.exaatto.client.ui.dialog;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Vincentas
 *
 */
public abstract class TextBoxDialog extends DialogBox {

	private static TextBoxDialogUiBinder uiBinder = GWT.create(TextBoxDialogUiBinder.class);

	interface TextBoxDialogUiBinder extends UiBinder<Widget, TextBoxDialog> {
	}

	@UiField
	Button okButton;

	@UiField
	Button cancelButton;
	
	@UiField
	TextBox textBox;

	public TextBoxDialog() {
		super(true, false);
		setWidget(uiBinder.createAndBindUi(this));
	}
	
	@UiHandler("okButton")
	void onOkClick(ClickEvent e) {
		hide();
		if (getText().length() != 0) {
			enteredText(getText());
		}
		textBox.setText("");
	}	
	
	abstract void enteredText(String text);
	
	@UiHandler("cancelButton")
	void onCancelClick(ClickEvent e) {
		hide();
	}
	
	public String getText() {
		return textBox.getText();
	}

}
